<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/10
  Time: 22:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>黄山学院-留学生信息管理系统</title>
    <link rel="stylesheet" href="/css/main_style.css" />
    <link rel="stylesheet" href="/css/message.css"/>
    <script src="/js/main_function.js"></script>
    <script>
        function messageCheck() {
            Ajax.post("/message/check", null, function (result) {
                // private Long user_id;
                // private String content;
                // private Date uptime;
                var results = JSON.parse(result);
                if (results.code == "100") {
                    var data = results.data;
                    var show = "<table>";
                    for (var i = 0; data[i] != null; i++) {
                        var uptime = new Date(data[i].uptime);
                        var time = formatDate(uptime);
                        show = show +
                            "<tr>" +
                            "<td>用户 " + data[i].user_id + "：</td>" +
                            "<td>" + data[i].content + "</td>" +
                            "<td>发送时间：" + time + "</td>" +
                            "</tr>"
                    }
                    show = show + "</table>";
                    document.getElementById("message-model").innerHTML = show;
                }
            });
        };

        function messageSend() {
            if (document.getElementById("message_content").value == "" || document.getElementById("message_content").value == null) {
                alert("留言为空！");
            } else {
                Ajax.post("/message/send", formJson("message"), function (result) {
                    var results = JSON.parse(result);
                    if (results.code == "100") {
                        messageCheck();
                        document.getElementById("message_content").value = "";
                    }
                })
            }
        }

        setTimeout('messageCheck()', 1000);
    </script>
</head>
<body onload="messageCheck()">
<div id="navigation">
    <div class="navigation-left"><img src="/img/school.png" style="width: 170px;height: 60px;"></img></div>
    <div class="navigation-center"><a>留言板</a></div>
    <div class="navigation-right">
        <div class="drop-menu" style="float:right;">
            <div class="user-menu"></div>
            <div class="drop-menu-content">
                <a href="/logout">注销登录</a>
                <a href="/rePassword">修改密码</a>
            </div>
        </div>
    </div>
</div>
<div id="broadside">
    <div class="broadside-logo">
        <h1>欢迎学生</h1>
        <p>${student_id}</p>
    </div>
    <div class="broadside-menu">
        <p><img src="/img/home.png"/><a href="/student/home">首页</a></p>
        <p><img src="/img/manager.png"/><a href="/student/manager">信息管理</a></p>
        <p><img src="/img/vacation.png"/><a href="/student/vacation">申请事假</a></p>
        <p><img src="/img/scholarship.png"/><a href="/student/scholarship">奖学金申请</a></p>
        <p><img src="/img/message.png"/><a href="/student/message">留言板</a></p>
    </div>
</div>
<div id="content">
    <div class="title"><p>留言版块</p></div>
    <div id="message-model">
    </div>
    <form id="message">
        <input type="text" name="content" id="message_content" value="">
    </form>
    <button type="button" onclick="messageSend()">发表留言</button>
</div>
</body>
</html>
